package com.tle.learnandroidlifetime;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class SubActivity1 extends Activity 
{

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // Properties //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////
																						// Properties //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
		
	
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{		
		Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onCreate");
		
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_sub_activity1);

//		if (savedInstanceState == null) 
//		{
//			getFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
//		}
		
		this.initGUI();
	}

	@Override
    protected void onStart() 
    {
    	// TODO Auto-generated method stub
		Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onStart");
    	
    	super.onStart();
    }
    
    @Override
    protected void onResume() 
    {
    	// TODO Auto-generated method stub
    	Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onResume");
    	super.onResume();
    }
    
    @Override
    protected void onPause() 
    {
    	// TODO Auto-generated method stub
    	Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onPause");
    	super.onPause();
    }
    
    @Override
    protected void onStop() 
    {
    	// TODO Auto-generated method stub
    	Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onStop");
    	super.onStop();
    }
    
    @Override
    protected void onDestroy() 
    {
    	// TODO Auto-generated method stub
    	Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onDestroy");
    	super.onDestroy();
    }
    
    @Override
    protected void onRestart() 
    {
    	// TODO Auto-generated method stub
    	Utilities.showToast(this, SubActivity1.class.getSimpleName() + " onRestart");
    	super.onRestart();
    }
	
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // Support Methods //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
	protected void initGUI ()
	{
		this.setTitle("This is sub activity 1 as dialog");
		
		// Don't work -> Must add android:theme="@android:style/Theme.Dialog" property in AndroidManifest.xml 
//		this.setTheme(android.R.style.Theme_Dialog);
		
		LinearLayout linearLayout = new LinearLayout(this);
		linearLayout.setOrientation(LinearLayout.VERTICAL);
		this.setContentView(linearLayout);
		
		Button btnBack = new Button(this);
		btnBack.setText("Come back main activity");
		btnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		linearLayout.addView(btnBack);
	}
    ////////////////////////////////////////////////////////////////////////////////////////////////////
																				   // Support Methods //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	
	
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // Override Methods //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.sub_activity1, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_sub_activity1,
					container, false);
			return rootView;
		}
	}
    ////////////////////////////////////////////////////////////////////////////////////////////////////
																				  // Override Methods //
    ////////////////////////////////////////////////////////////////////////////////////////////////////
}
